from flask import Blueprint, request, jsonify
from ..models import Turnout  # 假设 models.py 中有 Turnout 类型定义
from ..services import load_turnouts, save_turnouts, turnouts_from_json
blueprint_turnouts = Blueprint('turnouts', __name__, url_prefix='/api/turnouts')


@blueprint_turnouts.route('/load', methods=['GET'])
def load():
    # 假设有一个函数 load_turnouts() 用于加载道岔配置
    turnouts = load_turnouts()
    return jsonify(turnouts)

@blueprint_turnouts.route('/save', methods=['POST'])
def save():
    turnouts_data = turnouts_from_json(request.json)
    # 假设有一个函数 save_turnouts() 用于保存道岔配置
    save_turnouts(turnouts_data)
    return jsonify({"message": "Turnouts saved successfully"}), 200
